function createStore(reducer,initState){
    if(typeof reducer !== 'function'){
        throw new Error('reducer必须是函数')
    }
    //默认数据
    let currentState=initState;
    //默认reducer方法
    let currentReducer =reducer;
    //订阅池
    let currentList=[];
    //获取原来的数据
    function getState(){
        return currentState;
    }
    /*
    Object.getPrototypeOf  -->  __proto__

    纯对象的理解:实例的原型链(__proto__)===Object.prototype
    
    */
   function isObject(obj){
       if(typeof obj !== 'object'|| obj === null){
           return false;
       }
       return Object.getPrototypeOf(obj)===Object.prototype;
    // 找object最原始的值__proto__
   }
   function dispatch(action){
    //    dispatch({type:'add'})
       if(!isObject(action)){
           throw new Error ('action为对象')
       }
    // 发起action就到订阅池中，依次调用池子的函数
    // reducer(state={num:1},action)
   currentState=currentReducer(currentState,action);
   currentList.forEach(listener=>listener())
   };

function subscribe(listener){
    currentList.push(listener);
    //订阅监听回调函数，解绑监听状态
    return function (){
        let index=currentList.indexOf(listener)
        currentList.splice(index,1);
    }
}
dispatch({type:'@_@'})
return {
    getState,
    dispatch,
    subscribe
}
}
export {createStore}